import React, { useRef, useState,useEffect } from 'react';
import services from '@/services/demo';
// import { MicroApp } from 'umi';
// import Guide from '@/components/Guide';
import { trim,browserRedirect } from '@/utils/format';
import { useModel,Link,history } from '@umijs/max';
import { Collapse, Space,Carousel, Row,Col,Card,Button, Empty } from 'antd';
const { Panel } = Collapse;
import styles from './index.less';

const HomePage: React.FC = () => {
  const { name } = useModel('global');
  const { initialState, setInitialState }:any = useModel('@@initialState');
  const [plist, setPlist] = useState([]);
  useEffect(() => { 
    const _hmenu = JSON.parse(localStorage.getItem(initialState.projectname+'HistoryMenu') as any) || [];
    _hmenu &&  setPlist(_hmenu || []);
    // getProjectList({}).then((res: any) => {
    //   console.log('===getProjectList==',res);
    //   if (res.appCode == 'S0000') {
    //     if (res.result.length) {
    //       setPlist(res.result)
    //     }
    //   }
    // });
  }, []);
  const gotoSystem = async (values:any)=>{
    console.log(values);
    // setInitialState((s:any) => ({ ...s, showMenu: true }));

    // history.push('/apphome/'+values.id);
    history.push(values.path);
  };
  return (
      <div className={styles.container}>
        <Card style={{ marginTop: 8,boxShadow:'none' }} title="最近使用" bordered={false}>
        {plist.length>0?plist.map((item:any,index)=>{
          return (
            <Link key={index} to={item?.path}>
              <Button style={{ width:'14%',height:'75px',margin:'15px' }}>
                {item?.name}
              </Button>
            </Link>
          )
        }):(<>
          <Empty />
        </>)}
      </Card>

         {/* <h1 className={styles.tc_h_1}>最近打开</h1>
        <Row gutter={[16, 24]}>
          {
            plist.map((_item:any)=>{
              return (
                <Col
                  className="gutter-row"
                  key={'home_indexsystem_'+_item.id}
                  xs={12} sm={8} md={6} lg={6} xl={4}
                >
                  <Card bordered={false} hoverable className="tc_home_t1">
                      <p className={styles.tc_h_7}></p>
                      <p ><Button onClick={()=>gotoSystem(_item)}>进入系统</Button></p>
                      {_item.name}
                  
                  </Card>
                </Col>
              )
            })
          }
        </Row> */}
      </div>
  );
};

export default HomePage;
